﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Server.Models;
using Server.ManagerManage;
using Server.AuthManage;
using Server.CompanyManage;
using Server.UserManage;
using Server.AdsManage;

namespace Server.Share
{
    public class MShare
    {
        /// <summary>
        /// 管理员信息
        /// </summary>
        public ManagerModel manager = new ManagerModel();
        public ManagerBLL managerCtrl = new ManagerBLL();
        public AuthBLL authCtrl = new AuthBLL();
        public CompanyBLL companyCtrl = new CompanyBLL();
        public UserBLL userCtrl = new UserBLL();
        public AdsBLL adsCtrl = new AdsBLL();
        public void CheckInfo(string Token)
        {
            try
            {
                if (!string.IsNullOrEmpty(Token))
                {
                    
                    //验证Token
                    if (!managerCtrl.CheckManager(Token))
                        throw new Exception("验证用户出错,请重新登录!");
                    //获取管理员信息
                    manager = managerCtrl.GetManagerByToken(Token);
                }
                
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool CheckAuth(int id, string key)
        {
            try
            {
                if (id == 1)
                    return true;
                if (id < 1)
                    throw new Exception("用户ID错误！");
                if (string.IsNullOrEmpty(key))
                    throw new Exception("权限信息错误！");
                return authCtrl.CheckAuth(id, key);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
